import axios from 'axios'
import baseUrl from '../api/baseURL'
import store from '@/store'

const service = axios.create({
  baseURL: baseUrl,
  timeout: 15000
})

// request 请求拦截
service.interceptors.request.use(
  config => {
    if (store.state.token) {
      config.headers.token = window.sessionStorage.getItem('token')
    }
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

export default service
